package com.example.statistics.ui.purchase

import android.os.Bundle
import android.view.View
import androidx.constraintlayout.widget.ConstraintLayout.LayoutParams
import com.example.statistics.bean.PurchaseProductBean
import com.example.statistics.ex.*
import com.example.statistics.net.UrlConfig
import kotlinx.android.synthetic.main.activity_base_pruchase_product.*
import kotlinx.android.synthetic.main.activity_port_info_edit.*
import org.jetbrains.anko.dip
import kotlin.math.abs

class PurchaseSpotProductActivity : BasePurchaseProductActivity() {


    override val billTotalAmount: Double
        get() = purchaseProductBean?.productTotalPrice
                ?.addEx(clearanceFee)
                .addEx(storageFee).toDouble()

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        futuresFee = purchaseProductBean?.productTotalPrice.orEmpty()
        tv_start_time.visibility = View.GONE
        tv_ship_company.visibility = View.GONE
    }


    override fun refreshFee() {
        layout_fee.visibility = View.VISIBLE
        val list = mutableListOf<String>()
        val differenceFee = billTotalAmount.subEx(settlementTotalAmount).toDouble() //付款总金额与商品总价之间差价
        val differenceStatus = if (differenceFee > 0) "欠" else if (differenceFee == 0.0) "" else "多"
        val profit = purchaseProductBean?.salesTotalAmount.subEx(billTotalAmount)
                .subEx(purchaseProductBean?.purchaseSalesList?.sumEx { it.freight + it.unloadingFee }).toDouble() //利润
        val profitStatus = if (profit > 0.0) "赢" else if (profit < 0.0) "亏" else "" //
        list.add("商品总价：${purchaseProductBean?.productTotalPrice}")
        list.add("清        关：${clearanceFee.display()}")
        list.add("仓        储：${storageFee.display()}")
        list.add("成本单价：${billTotalAmount.mulEx(10).divEx(productValuationWeight).display()}")
        list.add("总  成  本：${billTotalAmount.display()}")
        list.add("")
        list.add("结算金额：${settlementTotalAmount.display()}")
        list.add("销售单价：${purchaseProductBean?.salesTotalAmount.mulEx(10).divEx(productValuationWeight).display()}")
        list.add("结算差价：${differenceStatus}${abs(differenceFee)}")
        list.add("利        润：${profitStatus}${abs(profit)}")
        recycler_view_fee.visibility = View.VISIBLE
        feeDetailAdapter?.setDataList(list)

        recycler_view_fee
    }

}